﻿using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Diagnostics;
using System.Threading;
using ExcelRefresh;
using System.Threading.Tasks;
using ExcelRefresh.Excel;

namespace ExcelRefreshCmd
{
    class Program
    {
        static void Main(string[] args)
        {
            TestNewExcelEngine();
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
        }


        private static void TestNewExcelEngine()
        {
            var queue = new ConcurrentQueue<FileToRefresh>();

            try
            {
                using (new FileScavenger(Settings.FoldersToScan, queue))
                using (new ExcelRefreshEngine(
                    Settings.MaxThreads,
                    Settings.RefreshTimeout,
                    queue))
                {
                    Trace.WriteLine("Engine running. Press any key to exit...");
                    Console.ReadKey();
                }
            }
            catch (ThreadAbortException ex)
            {
                Thread.ResetAbort();
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
                throw;
            }
        }
    }
}
